package com.ittsang.controller;

import com.ittsang.dto.ClubApplicationDTO;
import com.ittsang.dto.PageDTO;
import com.ittsang.dto.R;
import com.ittsang.mapper.UserMapper;
import com.ittsang.service.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/audit")
public class AuditController {

    @Resource
    private UserApplicationService userApplicationService;

    @Resource
    private UserService userService;

    @Resource
    private ArticleService articleService;

    @Resource
    private ExcelService excelService;

    @Resource
    private clubApplicationService clubApplicationService;

    /**
     *  获取申请加入本社团的人员
     * @return
     */
    @PostMapping("/getClubAuditUser")
    public R getClubAuditUser(@RequestBody PageDTO pageDTO) {
        return userApplicationService.getClubAuditUser(pageDTO);
    }

    /**
     *  审核不通过接口(申请加入本社团的人员)
     * @param userApplicationId
     * @return
     */
    @GetMapping("/isAuditUser")
    public R isAuditUser(@RequestParam("userApplicationId") Integer userApplicationId) {
        return userApplicationService.isAuditUser(userApplicationId);
    }

    /**
     *  审核通过名单(申请加入本社团的人员)
     * @param userApplicationId
     * @return
     */
    @GetMapping("/isOkAuditUser")
    public R isOkAuditUser(@RequestParam("userApplicationId") Integer userApplicationId) {
        return userApplicationService.isOkAuditUser(userApplicationId);
    }

    /**
     *  获取用户信息
     * @param userId
     * @return
     */
    @GetMapping("/getUserById")
    public R getUserById(@RequestParam("userId") Integer userId) {
        return userService.getUserById(userId);
    }

    /**
     *  获取所有文章，包括未审核
     * @param pageDTO
     * @return
     */
    @PostMapping("/getAuditArticle")
    public R getAuditArticle(@RequestBody PageDTO pageDTO) {
        return articleService.getAuditArticle(pageDTO);
    }

    /**
     *  获取参加人员名单，并且导出excel表
     * @param raceId
     * @return
     */
    // 目前还使用不了
    @GetMapping("/raceExcel")
    public void raceExcel(@RequestParam("raceId") Integer raceId, HttpServletResponse response) {
        excelService.raceExcel(raceId, response);
    }

    /**
     *  获取社团申请列表
     * @param pageDTO
     * @return
     */
    @PostMapping("/getAuditClub")
    public R getAuditClub(@RequestBody PageDTO pageDTO) {
        return clubApplicationService.getAuditClub(pageDTO);
    }

    /**
     *  申请社团接口，只有不是社团的人方可申请
     * @param clubApplicationDTO
     * @return
     */
    @PostMapping("/clubApplication")
    public R clubApplication(@RequestBody ClubApplicationDTO clubApplicationDTO) {
        return clubApplicationService.clubApplication(clubApplicationDTO);
    }

    /**
     *  审核通过社团申请
     * @param clubApplicationId
     * @return
     */
    @GetMapping("/auditClubApplication")
    public R auditClubApplication(@RequestParam("clubApplicationId") Integer clubApplicationId) {
        return clubApplicationService.auditClubApplication(clubApplicationId);
    }

    /**
     *  审核不通过社团申请
     * @param clubApplicationId
     * @return
     */
    @GetMapping("/auditNoClubApplication")
    public R auditNoClubApplication(@RequestParam("clubApplicationId") Integer clubApplicationId) {
        return clubApplicationService.auditNoClubApplication(clubApplicationId);
    }
}
